import sys,httplib
from time import strftime, localtime
from datetime import timedelta, date, datetime
import calendar
import time

stockcode=sys.argv[1]
#var hq_str_sh601890="8.20,8.30,8.34,8.38,8.20,8.34,8.35,8915001,73998575,69978,8.34,29701,8.33,33474
#http://hq.sinajs.cn/rn=1350562375061&list=sh601890
conn = httplib.HTTPConnection("hq.sinajs.cn")
conn.request("GET", "/rn=%d&list=%s" % (time.time()*1000, stockcode))
r1 = conn.getresponse()
data = r1.read()
seq = data.split(",")
curprice=float(seq[3])
if curprice > 20:
  sys.exit()
#print curprice 
#http://market.finance.sina.com.cn/pricehis.php?symbol=sh601890&startdate=2012-10-10&enddate=2012-10-17

#d=date.today()-timedelta(days=100)
#d=d.strftime("%Y%m%d")
d1=date.today().strftime("%Y-%m-%d")
d2=(date.today()-timedelta(days=240)).strftime("%Y-%m-%d")
#print d1, d2

conn = httplib.HTTPConnection("market.finance.sina.com.cn")
conn.request("GET", "/pricehis.php?symbol=%s&startdate=%s&enddate=%s"%(stockcode,d2,d1))
print "market.finance.sina.com.cn/pricehis.php?symbol=%s&startdate=%s&enddate=%s"%(stockcode,d2,d1)
r1 = conn.getresponse()
#print r1.status, r1.reason
data = r1.read()
pos=data.find("datalist")
#print pos
pos1=data.find("<tr", pos)
pos1=data.find("<tr", pos1+1)
pos2=data.find("</tbody", pos)
#print pos1,pos2
data = data[pos1:pos2].strip()
#print data
seq = data.split("<tr")
res=dict()
for i in seq:
  if len(i) < 10:
    #print "err"
    continue
  tmpseq = i.split("</td>")
  #print tmpseq
  price=tmpseq[0].strip()[tmpseq[0].strip().find("<td>")+4:]
  total=tmpseq[2].strip()[tmpseq[2].strip().find("<td>")+4:]
  #print "@--", price,total
  if float(price) not in res:
    res[float(price)]=float(total[:-1])
  else:
    res[float(price)]+=float(total[:-1])
keys=res.keys()
keys.sort()
#for i in keys:
#  print i,res[i]

#for i in keys:
#  print i, res[i]
#curprice=8.40
pos=keys.index(curprice)
tprice=int(curprice*1.15*100)/100.0
count=len(keys)
try:
  count=keys.index(tprice)
except:
  pass
count=count-pos
#print tprice,pos,count 
#count=keys.index(curprice)
#count1=int(curprice*0.02*100)
#print count
#count=10
i=0
s1=0
s2=0
flag=True
while i<count:
  if pos-i < 0:
    flag=False
    break 
  s1=s1+res[keys[pos-i]]
  i+=1
i=0
while i<count:
  if pos+i >= len(keys):
    flag=False
    break
  s2=s2+res[keys[pos+i]]
  i+=1
#print count
if s1>s2*5 and flag:
  print stockcode, curprice, "yes", s1, s2
else:
  print stockcode, curprice, "no", s1, s2, count, pos
#print curprice
#print res
#print s1,s2
